import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter);
let router = new VueRouter({
    mode:'hash',
    routes:[
        {
            path:'/register',
            name:'register',
            component:()=>import('../pages/Register.vue')
        },{
            path:'/login',
            name:'login',
            component:()=>import('../pages/Login.vue')
        },{
            path:'/content',
            name:'content',
            component:()=>import('../pages/Content.vue'),
            children:[
                {
                    path:'shouye',
                    name:'shouye',
                    component:()=>import('../pages/content/ShouYe.vue')
                },{
                    path:'/content/stuinfo',
                    name:'stuinfo',
                    component:()=>import('../pages/content/StuInfo.vue')
                },{
                    path:'/content/stushow',
                    name:'stushow',
                    component:()=>import('../pages/content/StuShow.vue')
                },{
                    path:'/content/stushowhou',
                    name:'stushowhou',
                    component:()=>import('../pages/content/StuShowHou.vue')
                }
            ]
        },{
            path:'/',
            redirect:'/content/shouye'
        }
    ]
})
// 
let pathsArr = ['/content/stushow','/content/stushowhou'];
router.beforeEach((to,from,next)=>{
    console.log(to);
    console.log(from);
    if(pathsArr.indexOf(to.path)>=0){
        // to.path 在pathsArr中
        // 判断是否登录
        console.log(Vue.store.state);
        if(Vue.store.state.user_name){
            next();
        }else{
            next('/login')
        }
        // next();
    }else{
        // 放行
        next();
    }
    next();
})

export default router


/* 
需求 当登录后 能进入学生信息展示和学生信息后台分页展示



*/